package com.linuxone.news;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class TodayNews implements Serializable  {

	private static final long serialVersionUID = 5537048485706162060L;
	
	private Map<String, NewsThread> db = new HashMap<String, NewsThread>();
	
	public NewsThread getNewsThread(String key) {
		NewsThread ret = db.get(key);
		if (ret == null)
			return new NewsThread();
		else
			return ret;
	}
	
	public List<NewsThread> getAllNewsThreadinList(){
		List<NewsThread> myList = new ArrayList<NewsThread>(db.values());
		Collections.sort(myList, new Comparator<NewsThread>(){
			@Override
			public int compare(final NewsThread arg0, final NewsThread arg1) {
				return arg1.getDate().compareTo(arg0.getDate());
			}
		});
		return myList; 
	}
	
	public Map<String, NewsThread> getAllNewsThread() {
		return db;
	}
	
	public int getLength() {
		return db.size();
	}
	
	public List<String> getDateTime() {
		List<String> list = new ArrayList<String>(db.keySet());
		Collections.sort(list);
		return list;
	}
	
	public void addNewsThread(NewsThread news) {
		db.put(news.getId(), news);
	}
}